package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing_project")
@Api( tags = "护理项目")
public class NursingProjectController extends BaseController {
    @Autowired
    private NursingProjectService nursingProjectService;
    @ApiOperation("分页查询护理项目")
    @GetMapping
    public ResponseResult<PageResponse<NursingProjectVo>> getPage(
           @ApiParam(value = "名称",required = false) @RequestParam(value = "name",required = false) String name,
           @ApiParam(value = "当前页",required = true) @RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
           @ApiParam(value = "每页显示条数",required = true ) @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize,
           @ApiParam(value = "状态（0:禁用，1:启用）",required = false) @RequestParam(value = "status",required = false) Integer status
    ){
        PageResponse<NursingProjectVo> page = nursingProjectService.getPage(name, status, pageNum, pageSize);
        return success(page);
    }
    @PostMapping
    public ResponseResult add (@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }
    //根据id查询
    @GetMapping("/{id}")
    public  ResponseResult<NursingProjectVo> getById(@PathVariable ("id")Long id){
       NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }
    @PutMapping
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }
}
